package com.bigtotoro.shuiyincamera;

import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.bigtotoro.shuiyincamera.image.AddWaterMark02Activity;
import com.bigtotoro.shuiyincamera.image.Palette02Activity;
import com.bigtotoro.shuiyincamera.image.RemoveWaterMark2Activity;
import com.bigtotoro.shuiyincamera.image.RemoveWaterMarkActivity;
import com.bigtotoro.shuiyincamera.model.BaseResponse;
import com.bigtotoro.shuiyincamera.model.VersionDetails;
import com.bigtotoro.shuiyincamera.model.VersionResponse;
import com.bigtotoro.shuiyincamera.util.FileUtils;
import com.bigtotoro.shuiyincamera.util.ModelSingle;
import com.bigtotoro.shuiyincamera.util.VideoItem;
import com.bigtotoro.shuiyincamera.util.VideoUtil;
import com.bigtotoro.shuiyincamera.util.SharedPreferencesUtil;
import com.bigtotoro.shuiyincamera.video.VideoAddWater2Activity;
import com.bigtotoro.shuiyincamera.video.VideoCropActivity;
import com.bigtotoro.shuiyincamera.video.VideoFilterActivity;
import com.bigtotoro.shuiyincamera.video.VideoMusicActivity;
import com.bigtotoro.shuiyincamera.video.VideoConcatActivity;
import com.bigtotoro.shuiyincamera.util.MyUtils;
import com.bigtotoro.shuiyincamera.video.VideoRemoveWaterActivity;
import com.bigtotoro.shuiyincamera.video.VideoSpeedActivity;
import com.bigtotoro.shuiyincamera.video.trim.VideoTrimmerActivity;
import com.google.gson.Gson;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.umeng.analytics.MobclickAgent;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import static com.bigtotoro.shuiyincamera.Constant.SP_XIEYI;

public class Main2Activity extends AppCompatActivity implements View.OnClickListener {
    private View item;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        findViewById(R.id.btn_setting).setOnClickListener(this);

        findViewById(R.id.btn_img_add_watermark).setOnClickListener(this);//图片加水印
        findViewById(R.id.btn_img_remove_watermark).setOnClickListener(this);//图片去水印，还没有这个功能，调用的图片裁剪
        findViewById(R.id.btn_img_palette).setOnClickListener(this);//图片涂鸦

        findViewById(R.id.btn_video_add_watermark).setOnClickListener(this);//视频加水印
        findViewById(R.id.btn_video_remove_water).setOnClickListener(this);//视频去水印
        findViewById(R.id.btn_video_splice).setOnClickListener(this);//视频拼接
        findViewById(R.id.btn_video_cut).setOnClickListener(this);//视频剪裁
        findViewById(R.id.btn_video_edit).setOnClickListener(this);//视频分割
        findViewById(R.id.btn_video_music).setOnClickListener(this);//背景音乐
        findViewById(R.id.btn_video_extract_bg).setOnClickListener(this);//分离音频
        findViewById(R.id.btn_video_speed).setOnClickListener(this);//视频加减速
        findViewById(R.id.btn_video_daofang).setOnClickListener(this);//视频加减速
        findViewById(R.id.btn_video_gif).setOnClickListener(this);//视频加减速
        findViewById(R.id.btn_video_lvjing).setOnClickListener(this);//视频加减速

        findViewById(R.id.btn_music_edit).setOnClickListener(this);//音频分割

        item = findViewById(R.id.item);

    }

    public static final int SELECT_IMAGE_ADD_WATER_MARK = 1001;
    public static final int SELECT_IMAGE_CUT = 1002;
    public static final int SELECT_IMAGE_FREE_EDIT = 1003;
    public static final int SELECT_IMAGE_REMOVE_WATER_MARK = 1004;
    public static final int SELECT_MUSIC_CROP = 1005;

    public static final int SELECT_VIDEO_REMOVE_WATER_MARK = 1007;
    public static final int SELECT_VIDEO_ADD_WATER_MARK = 1008;
    public static final int SELECT_VIDEO_EDIT = 1009;
    public static final int SELECT_VIDEO_CROP = 1010;
    public static final int SELECT_VIDEO_MUSIC = 1011;
    public static final int SELECT_VIDEO_SPLICE = 1012;
    public static final int SELECT_VIDEO_EXTRACT_BG = 1013;
    public static final int SELECT_VIDEO_SPEED = 1014;
    public static final int SELECT_VIDEO_DAOFANG = 1015;
    public static final int SELECT_VIDEO_GIF = 1016;
    public static final int SELECT_VIDEO_LVJING = 1017;
    public static final int REQUEST_PERMISSON_SORAGE = 1;
    private int mRequestCode = -1;
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_setting: //设置界面
                startActivity(new Intent(Main2Activity.this,SettingActivity.class));
                break;
            case R.id.btn_video_speed: //视频加减速
                Log.i("视频处理","视频加减速");
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_VIDEO_SPEED;
                            selectFromAblum();
                        }
                    }
                });
                break;
            case R.id.btn_video_daofang: //视频倒放
                Log.i("视频处理","视频倒放");
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_VIDEO_DAOFANG;
                            selectFromAblum();
                        }
                    }
                });
                break;
            case R.id.btn_video_gif: //视频gif导出
                Log.i("视频处理","视频gif导出");
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_VIDEO_GIF;
                            selectFromAblum();
                        }
                    }
                });
                break;
            case R.id.btn_video_remove_water://视频去水印
                Log.i("视频处理","视频去水印");
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_VIDEO_REMOVE_WATER_MARK;
                            selectFromAblum();
                        }
                    }
                });
                break;
            case R.id.btn_video_add_watermark://视频加水印
                Log.i("视频处理","视频加水印");
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_VIDEO_ADD_WATER_MARK;
                            selectFromAblum();
                        }
                    }
                });
                break;
            case R.id.btn_video_splice://视频拼接
                Log.i("视频处理","视频拼接");
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_VIDEO_SPLICE;
                            selectFromAblum();
                        }
                    }
                });
                break;
            case R.id.btn_video_cut://视频剪裁
                Log.i("视频处理","视频剪裁");
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_VIDEO_CROP;
                            selectFromAblum();
                        }
                    }
                });
                break;
            case R.id.btn_video_edit://视频分割
                Log.i("视频处理","视频分割");
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_VIDEO_EDIT;
                            selectFromAblum();
                        }
                    }
                });
                break;
            case R.id.btn_video_music://背景音乐
                Log.i("视频处理","背景音乐");
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_VIDEO_MUSIC;
                            selectFromAblum();
                        }
                    }
                });
                break;
            case R.id.btn_video_extract_bg://分离音频
                Log.i("视频处理","背景音乐");
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_VIDEO_EXTRACT_BG;
                            selectFromAblum();
                        }
                    }
                });
                break;


            case R.id.btn_img_add_watermark:  //图片加水印
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_IMAGE_ADD_WATER_MARK;
                            selectFromAblum();
                        }
                    }
                });
                break;
            case R.id.btn_img_remove_watermark:  //图片去水印
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_IMAGE_REMOVE_WATER_MARK;
                            selectFromAblum();
                        }
                    }
                });
                break;
            case R.id.btn_img_palette:  //画板涂鸦
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_IMAGE_FREE_EDIT;
                            selectFromAblum();
                        }
                    }
                });
                break;

            case R.id.btn_video_lvjing:  //视频滤镜
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_VIDEO_LVJING;
                            selectFromAblum();
                        }
                    }
                });
                break;

            case R.id.btn_music_edit:  //音频分割
                MyUtils.checkReadAndWritePermission(Main2Activity.this, new MyUtils.IntegerCallback() {
                    @Override
                    public void callback(int data) {
                        if (data>0){
                            mRequestCode = SELECT_MUSIC_CROP;
                            selectFromAblum();
                        }
                    }
                });
                break;
        }
    }

    /**
     * 从相册选择编辑图片
     */
    private void selectFromAblum() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            openAblumWithPermissionsCheck();
        } else {
            openAblum();
        }
    }

    private void openAblumWithPermissionsCheck() {
        if (ActivityCompat.checkSelfPermission(Main2Activity.this,
                Manifest.permission.READ_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(Main2Activity.this,
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                    REQUEST_PERMISSON_SORAGE);
            return;
        }
        openAblum();
    }

    private void openAblum() {
        switch (mRequestCode){
            case SELECT_VIDEO_SPEED://视频加减速
                Log.i("视频处理","openAblum 视频加减速");
                PictureSelector.create(this).openGallery(PictureMimeType.ofVideo())
                        .previewVideo(true).selectionMode(PictureConfig.SINGLE).videoMinSecond(1).forResult(mRequestCode);
                break;
            case SELECT_VIDEO_DAOFANG://视频倒放
                Log.i("视频处理","openAblum 视频倒放");
                PictureSelector.create(this).openGallery(PictureMimeType.ofVideo())
                        .previewVideo(true).selectionMode(PictureConfig.SINGLE).videoMinSecond(1).forResult(mRequestCode);
                break;
            case SELECT_VIDEO_GIF://视频GIF导出
                Log.i("视频处理","openAblum 视频GIF导出");
                PictureSelector.create(this).openGallery(PictureMimeType.ofVideo())
                        .previewVideo(true).selectionMode(PictureConfig.SINGLE).videoMinSecond(1).forResult(mRequestCode);
                break;
            case SELECT_VIDEO_LVJING:
                PictureSelector.create(this).openGallery(PictureMimeType.ofVideo())
                        .previewVideo(true).selectionMode(PictureConfig.SINGLE).videoMinSecond(1).forResult(mRequestCode);
                break;
            case SELECT_VIDEO_ADD_WATER_MARK://视频加水印
                Log.i("视频处理","openAblum 视频加水印");
                PictureSelector.create(this).openGallery(PictureMimeType.ofVideo())
                        .previewVideo(true).selectionMode(PictureConfig.SINGLE).videoMinSecond(1).forResult(mRequestCode);
                break;
            case SELECT_VIDEO_REMOVE_WATER_MARK://视频去水印
                Log.i("视频处理","openAblum 视频去水印");
                PictureSelector.create(this).openGallery(PictureMimeType.ofVideo())
                        .previewVideo(true).selectionMode(PictureConfig.SINGLE).videoMinSecond(1).forResult(mRequestCode);
                break;
            case SELECT_VIDEO_EDIT://视频分割
                Log.i("视频处理","openAblum 视频分割");
                PictureSelector.create(this).openGallery(PictureMimeType.ofVideo())
                        .previewVideo(true).selectionMode(PictureConfig.SINGLE).videoMinSecond(1).forResult(mRequestCode);
                break;
            case SELECT_VIDEO_CROP://视频剪裁
                Log.i("视频处理","openAblum 视频剪裁");
                PictureSelector.create(this).openGallery(PictureMimeType.ofVideo())
                        .previewVideo(true).selectionMode(PictureConfig.SINGLE).videoMinSecond(1).forResult(mRequestCode);
                break;
            case SELECT_VIDEO_MUSIC://背景音乐
                Log.i("视频处理","openAblum 背景音乐");
                PictureSelector.create(this).openGallery(PictureMimeType.ofVideo())
                        .previewVideo(true).selectionMode(PictureConfig.SINGLE).videoMinSecond(1).forResult(mRequestCode);
                break;
            case SELECT_VIDEO_EXTRACT_BG://背景音乐
                Log.i("视频处理","openAblum 提取音频");
                PictureSelector.create(this).openGallery(PictureMimeType.ofVideo())
                        .previewVideo(true).selectionMode(PictureConfig.SINGLE).videoMinSecond(1).forResult(mRequestCode);
                break;
            case SELECT_VIDEO_SPLICE://视频拼接
                Log.i("视频处理","openAblum 视频拼接"); //最多5个
                PictureSelector.create(this).openGallery(PictureMimeType.ofVideo())
                        .previewVideo(true).maxSelectNum(5).selectionMode(PictureConfig.MULTIPLE).videoMinSecond(1).forResult(mRequestCode);
                break;
            case SELECT_MUSIC_CROP://音频分割
                Log.i("视频处理","openAblum 视频拼接"); //最多5个
                PictureSelector.create(this).openGallery(PictureMimeType.ofAudio())
                        .previewVideo(true).selectionMode(PictureConfig.SINGLE).videoMinSecond(1).forResult(mRequestCode);
                break;
            default:
                PictureSelector.create(this).openGallery(PictureMimeType.ofImage())
                        .previewVideo(true).selectionMode(PictureConfig.SINGLE).videoMinSecond(1).forResult(mRequestCode);
//                startActivityForResult(new Intent(Main2Activity.this, SelectPictureActivity.class),
//                    mRequestCode);
                break;
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if (requestCode == REQUEST_PERMISSON_SORAGE
                && grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            openAblum();
            return;
        }
    }

    private String saveFilePath;
    private int imageWidth, imageHeight;
    private void handleEditorImage(Intent data) {
//        String newFilePath = data.getStringExtra(ImageEditorIntentBuilder.OUTPUT_PATH);
//        boolean isImageEdit = data.getBooleanExtra(EditImageActivity.IS_IMAGE_EDITED, false);

//        if (isImageEdit) { //编辑成功
//            //保存图片并进入我的作品
//            saveFilePath = outputFile.getAbsolutePath();
//            Toast.makeText(Main2Activity.this, getString(R.string.save_path, saveFilePath), Toast.LENGTH_LONG).show();
//            //放入图片列表
//            DisplayMetrics metrics = getResources().getDisplayMetrics();
//            imageWidth = metrics.widthPixels;
//            imageHeight = metrics.heightPixels;
//
//            MyArt art = new MyArt();
//            art.setHeight(imageHeight);
//            art.setWidth(imageWidth);
//            Long millis = System.currentTimeMillis();
//            art.setCreate_time(millis + "");
//            art.setPath(saveFilePath);
//            art.setType(1); //加水印
//            art.save();
//
//            Intent intent = new Intent(Main2Activity.this, ShowMyArtsActivity.class);
//            intent.putExtra(EXTRA_OUTPUT, saveFilePath);
//            intent.putExtra("width", imageHeight);
//            intent.putExtra("height", imageWidth);
//
//            FileUtil.ablumUpdate(Main2Activity.this, saveFilePath);//更新相册
//            startActivity(intent);
//            finish();
//
//
//        } else {
////            newFilePath = data.getStringExtra(ImageEditorIntentBuilder.SOURCE_PATH);
//
//        }



    }

    private File outputFile;
    private List<LocalMedia> paths;
    public static final int ACTION_REQUEST_EDITIMAGE = 9;
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /**
         * 选择图片后返回
         * **/
        if (resultCode == RESULT_OK) {
            String filepath = data.getStringExtra("imgPath");
            //原始图片存储地址
            switch (requestCode) {
                case SELECT_IMAGE_REMOVE_WATER_MARK://图片去水印

                    List<LocalMedia> selectlist01 = PictureSelector.obtainMultipleResult(data);
                    if(selectlist01.size()>0){
                        //验证成功，可以正确的去除选定区域的水印
                        startActivity(new Intent(Main2Activity.this, RemoveWaterMark2Activity.class)
                                .putExtra("path",selectlist01.get(0).getPath())
                                .putExtra("img-width",selectlist01.get(0).getWidth())
                                .putExtra("img-height",selectlist01.get(0).getHeight())
                        );
//                        startActivity(new Intent(Main2Activity.this, RemoveWaterMarkActivity.class)
//                                .putExtra("path",selectlist01.get(0).getPath())
//                                .putExtra("img-width",selectlist01.get(0).getWidth())
//                                .putExtra("img-height",selectlist01.get(0).getHeight())
//                        );
                    }

//                    startActivity(new Intent(Main2Activity.this, RemoveWaterMarkActivity.class)
//                            .putExtra("path", filepath));
                    break;
                case SELECT_IMAGE_ADD_WATER_MARK://图片加水印
                    List<LocalMedia> selectlist02 = PictureSelector.obtainMultipleResult(data);
                    if(selectlist02.size()>0){
                        //验证成功，可以正确的去除选定区域的水印
                        startActivity(new Intent(Main2Activity.this, AddWaterMark02Activity.class)
                                .putExtra("path",selectlist02.get(0).getPath()));
                    }
                    break;
//                case SELECT_IMAGE_CUT://裁剪
//                    startActivity(new Intent(Main2Activity.this, Cut02Activity.class)
//                            .putExtra("path", filepath));
//                    break;
                case SELECT_IMAGE_FREE_EDIT://自由编辑
                    List<LocalMedia> selectlist03 = PictureSelector.obtainMultipleResult(data);
                    if(selectlist03.size()>0){
                        String inputPath = selectlist03.get(0).getPath(); //输入路径
                        outputFile = FileUtils.genEditFile();//输出路径
//                        try {
//                            Intent intent = new ImageEditorIntentBuilder(this, inputPath, outputFile.getAbsolutePath())
//                                    .withAddText()
//                                    .withPaintFeature()
//                                    .withFilterFeature()
//                                    .withRotateFeature()
//                                    .withCropFeature()
//                                    .withBrightnessFeature()
//                                    .withSaturationFeature()
//                                    .withBeautyFeature()
//                                    .forcePortrait(true)
//                                    .build();
//
//                            EditImageActivity.start(this, intent, ACTION_REQUEST_EDITIMAGE);
//                        } catch (Exception e) {
//                            Toast.makeText(this, R.string.iamutkarshtiwari_github_io_ananas_not_selected, Toast.LENGTH_SHORT).show();
//                            Log.e("Demo App", e.getMessage());
//                        }

                        startActivity(new Intent(Main2Activity.this, Palette02Activity.class)
                                .putExtra("path",selectlist03.get(0).getPath()));
//                        startActivity(new Intent(Main2Activity.this, Palette02Activity.class)
//                                .putExtra("path",selectlist03.get(0).getPath()));
                    }
                    break;
                case ACTION_REQUEST_EDITIMAGE: //自由编辑返回
                    handleEditorImage(data);
                    break;


                case SELECT_VIDEO_REMOVE_WATER_MARK: //视频去水印
                    Log.i("视频处理","onActivityResult 视频去水印");
                    List<LocalMedia> selectList2 = PictureSelector.obtainMultipleResult(data);
                    if(selectList2.size()>0){
                        //验证成功，可以正确的去除选定区域的水印
                        MyUtils.checkOrcopyFile(selectList2.get(0).getPath(), new MyUtils.StrCallback() {
                            @Override
                            public void callback(String path, int isNew) {
                                if (path!=null && path.length()>0){
                                    startActivity(new Intent(Main2Activity.this, VideoRemoveWaterActivity.class)
                                            .putExtra("path",path));
                                }
                            }
                        });
                    }
                    break;
                case SELECT_VIDEO_ADD_WATER_MARK: //视频加水印
                    Log.i("视频处理","onActivityResult 视频加水印");
                    List<LocalMedia> selectList3 = PictureSelector.obtainMultipleResult(data);
                    if(selectList3.size()>0){
                        //验证成功，可以正确的去除选定区域的水印
                        MyUtils.checkOrcopyFile(selectList3.get(0).getPath(), new MyUtils.StrCallback() {
                            @Override
                            public void callback(String path, int isNew) {
                                if (path!=null && path.length()>0){
                                    startActivity(new Intent(Main2Activity.this, VideoAddWater2Activity.class)
                                            .putExtra("path",path));
                                }
                            }
                        });
                    }
                    break;
                case SELECT_VIDEO_EDIT: //视频时长剪辑
                    Log.i("视频处理","onActivityResult 视频分割");
                    List<LocalMedia> selectList4 = PictureSelector.obtainMultipleResult(data);
                    if(selectList4.size()>0){
                        //验证成功，可以正确的去除选定区域的水印
                        String path = selectList4.get(0).getPath();
                        //视频分割界面
                        MyUtils.checkOrcopyFile(path, new MyUtils.StrCallback() {
                            @Override
                            public void callback(String path, int isNew) {
                                if (path!=null && path.length()>0){
                                    startActivity(new Intent(Main2Activity.this, VideoTrimmerActivity.class)
                                            .putExtra(VideoTrimmerActivity.VIDEO_PATH_KEY, path)
                                    );
                                }
                            }
                        });


//                        startActivity(new Intent(Main2Activity.this, VideoEditActivity.class)
//                                .putExtra("path",selectList4.get(0).getPath()));
                    }
                    break;
                case SELECT_VIDEO_CROP: //视频区域剪裁
                    Log.i("视频处理","onActivityResult 视频剪裁");
                    List<LocalMedia> selectList5 = PictureSelector.obtainMultipleResult(data);
                    if(selectList5.size()>0){
                        //验证成功，可以正确的去除选定区域的水印
                        MyUtils.checkOrcopyFile(selectList5.get(0).getPath(), new MyUtils.StrCallback() {
                            @Override
                            public void callback(String path, int isNew) {
                                if (path!=null && path.length()>0){
                                    startActivity(new Intent(Main2Activity.this, VideoCropActivity.class)
                                            .putExtra("path",path));
                                }
                            }
                        });
                    }
                    break;
                case SELECT_VIDEO_MUSIC: //背景音乐
                    Log.i("视频处理","onActivityResult 背景音乐");
                    List<LocalMedia> selectList6 = PictureSelector.obtainMultipleResult(data);
                    if(selectList6.size()>0){
                        //验证成功，可以正确的去除选定区域的水印
                        MyUtils.checkOrcopyFile(selectList6.get(0).getPath(), new MyUtils.StrCallback() {
                            @Override
                            public void callback(String path, int isNew) {
                                if (path!=null && path.length()>0){
                                    startActivity(new Intent(Main2Activity.this, VideoMusicActivity.class)
                                            .putExtra("path",path));
                                }
                            }
                        });

                    }
                    break;
                case SELECT_VIDEO_EXTRACT_BG: //提取音频
                    Log.i("视频处理","onActivityResult 分离音频");
                    List<LocalMedia> selectList9 = PictureSelector.obtainMultipleResult(data);
                    if(selectList9.size()>0){
                        String path = selectList9.get(0).getPath();
                        MyUtils.checkOrcopyFile(path, new MyUtils.StrCallback() {
                            @Override
                            public void callback(String path, int isNew) {
                                if (path!=null && path.length()>0){
                                    startActivity(new Intent(Main2Activity.this, VideoTrimmerActivity.class)
                                            .putExtra(VideoTrimmerActivity.VIDEO_PATH_KEY, path)
                                            .putExtra("mode", "extract_bg")
                                    );
                                }
                            }
                        });


                    }
                    break;
                case SELECT_VIDEO_SPLICE: //视频拼接
                    Log.i("视频处理","onActivityResult 视频拼接");
                    List<LocalMedia> selectList7 = PictureSelector.obtainMultipleResult(data);
                    if(selectList7.size()>0){
                        List<VideoItem> videos = new ArrayList<>();
                        for (LocalMedia media:selectList7){
                            MyUtils.checkOrcopyFile(media.getPath(), new MyUtils.StrCallback() {
                                @Override
                                public void callback(String path, int isNew) {
                                    if (path!=null && path.length()>0){
                                        media.setPath(path);
                                    }
                                }
                            });
                        }
                        for (LocalMedia media:selectList7){
                            videos.add(VideoUtil.createVideoItem(media.getPath()));
                        }
                        ModelSingle.getInstance().setMode2(videos);
//                        startActivity(new Intent(Main2Activity.this, VideoSpliceActivity.class));
                        startActivity(new Intent(Main2Activity.this, VideoConcatActivity.class));
                    }
                    break;
                case SELECT_MUSIC_CROP: //音频裁剪
                    Log.i("视频处理","onActivityResult 音频分割");
                    List<LocalMedia> selectList8 = PictureSelector.obtainMultipleResult(data);
                    if(selectList8.size()>0){
                        //路径检测
                        MyUtils.checkOrcopyFile(selectList8.get(0).getPath(), new MyUtils.StrCallback() {
                            @Override
                            public void callback(String str, int isNew) {
                                if (str!=null && str.length()>0){
                                    //验证成功，可以正确的去除选定区域的水印
                                    Log.i("newFileName","newFileName======"+str);
                                    startActivity(new Intent(Main2Activity.this, MusicCropActivity.class)
                                            .putExtra("path",str)
                                            .putExtra("isNew",isNew)
                                    );
                                }
                            }
                        });
                    }
                    break;
                case SELECT_VIDEO_SPEED: //视频加减速
                    Log.i("视频处理","onActivityResult 视频加减速");
                    List<LocalMedia> selectList10 = PictureSelector.obtainMultipleResult(data);
                    if(selectList10.size()>0){
                        //验证成功，可以正确的去除选定区域的水印
                        MyUtils.checkOrcopyFile(selectList10.get(0).getPath(), new MyUtils.StrCallback() {
                            @Override
                            public void callback(String path, int isNew) {
                                if (path!=null && path.length()>0){
                                    startActivity(new Intent(Main2Activity.this, VideoSpeedActivity.class)
                                            .putExtra("path",path));
                                }
                            }
                        });
                    }
                    break;
                case SELECT_VIDEO_DAOFANG: //视频倒放
                    Log.i("视频处理","onActivityResult 视频倒放");
                    List<LocalMedia> selectList11 = PictureSelector.obtainMultipleResult(data);
                    if(selectList11.size()>0){
                        //验证成功，可以正确的去除选定区域的水印
                        MyUtils.checkOrcopyFile(selectList11.get(0).getPath(), new MyUtils.StrCallback() {
                            @Override
                            public void callback(String path, int isNew) {
                                if (path!=null && path.length()>0){
                                    startActivity(new Intent(Main2Activity.this, VideoTrimmerActivity.class)
                                            .putExtra(VideoTrimmerActivity.VIDEO_PATH_KEY, path)
                                            .putExtra("mode", "daofang"));
                                }
                            }
                        });


                    }
                    break;
                case SELECT_VIDEO_GIF: //视频gif导出
                    Log.i("视频处理","onActivityResult 视频gif导出");
                    List<LocalMedia> selectList12 = PictureSelector.obtainMultipleResult(data);
                    if(selectList12.size()>0){
                        //验证成功，可以正确的去除选定区域的水印
                        MyUtils.checkOrcopyFile(selectList12.get(0).getPath(), new MyUtils.StrCallback() {
                            @Override
                            public void callback(String path, int isNew) {
                                if (path!=null && path.length()>0){
                                    startActivity(new Intent(Main2Activity.this, VideoTrimmerActivity.class)
                                            .putExtra(VideoTrimmerActivity.VIDEO_PATH_KEY, path)
                                            .putExtra("mode", "gif"));
                                }
                            }
                        });


                    }
                    break;
                case SELECT_VIDEO_LVJING:
                    Log.i("视频处理","onActivityResult 视频滤镜导出");
                    List<LocalMedia> selectList13 = PictureSelector.obtainMultipleResult(data);
                    if(selectList13.size()>0){
                        //验证成功，可以正确的去除选定区域的水印
                        MyUtils.checkOrcopyFile(selectList13.get(0).getPath(), new MyUtils.StrCallback() {
                            @Override
                            public void callback(String path, int isNew) {
                                if (path!=null && path.length()>0){
                                    startActivity(new Intent(Main2Activity.this, VideoFilterActivity.class)
                                            .putExtra("path", path)
                                    );
                                }
                            }
                        });
                    }
                    break;
            }
        }

    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("Main2Activity");//统计页面
        MobclickAgent.onResume(this);
    }
    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("Main2Activity");//统计页面
        MobclickAgent.onPause(this);
    }
}
